package com.loyi.cloud.hbsystem.cqi.task;

import java.util.Date;

import org.apache.commons.lang3.time.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.loyi.cloud.hbsystem.cqi.rest.CQITotalController;

@Component
public class CQITotalTask {

	@Autowired
	private CQITotalController cqiTotalController;

	@Scheduled(cron = "0 30 * * * ? ")
	public void totalHour() {
		cqiTotalController.total(new Date(), 0);
	}

	/**
	 * 每日凌晨1点开始统计前一日的日报
	 */
	@Scheduled(cron = "0 30 1 * * ? ")
	public void totalDay() {
		Date datatime = new Date();
		datatime = DateUtils.addDays(datatime, -1);
		cqiTotalController.total(datatime, 1);
	}

	/**
	 * 每日凌晨2点开始统计前一日的周报
	 */
	@Scheduled(cron = "0 30 2 * * ? ")
	public void totalWeek() {
		Date datatime = new Date();
		datatime = DateUtils.addDays(datatime,  -1);
		cqiTotalController.total(datatime, 2);
	}

	/**
	 * 每日凌晨3点开始统计前一日的月报
	 */
	@Scheduled(cron = "0 30 3 * * ? ")
	public void totalMonth() {
		Date datatime = new Date();
		datatime = DateUtils.addDays(datatime,  -1);
		cqiTotalController.total(datatime, 3);
	}

	/**
	 * 每日凌晨4点开始统计前一日的月报
	 */
	@Scheduled(cron = "0 30 4 * * ? ")
	public void totalQuarter() {
		Date datatime = new Date();
		datatime = DateUtils.addDays(datatime,  -1);
		cqiTotalController.total(datatime, 4);
	}

	/**
	 * 每日凌晨5点开始统计半年报
	 */
	@Scheduled(cron = "0 30 5 * * ? ")
	public void totalHalfyear() {
		Date datatime = new Date();
		datatime = DateUtils.addDays(datatime,  -1);
		cqiTotalController.total(datatime, 5);
	}

	/**
	 * 每日凌晨6点开始统计半年报
	 */
	@Scheduled(cron = "0 30 6 * * ? ")
	public void totalyear() {
		Date datatime = new Date();
		datatime = DateUtils.addDays(datatime,  -1);
		cqiTotalController.total(datatime, 6);
	}
}
